package com.example.pet.controller;

import com.example.pet.service.PetShowService;
import com.hj.pet.model.PetInfo;
import com.hj.pet.model.QueryCondition;
import com.hj.pet.model.ReturnT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/show")
public class PetShowController {
    @Autowired
    PetShowService petShowService;

    @RequestMapping(value = "save" , method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> save(@RequestBody PetInfo petInfo){
        return petShowService.save(petInfo);
    }

    @RequestMapping(value = "updateById",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> updateById(@RequestBody PetInfo petInfo){
        return petShowService.updateById(petInfo);
    }

    @RequestMapping(value = "findPetById",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findPetById(@RequestParam int petId) {
        return petShowService.findPetById(petId);
    }

    @RequestMapping(value = "findPetsByType",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findPetsByType(@RequestParam String type) {
        return petShowService.findPetsByType(type);
    }

    @RequestMapping(value = "findPetsByPrice",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findPetsByPrice(@RequestParam Integer price1, @RequestParam Integer price2) {
        return petShowService.findPetsByPrice(price1,price2);
    }

    @RequestMapping(value = "findPetsByUserAccount",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findPetsByUserAccount(@RequestParam String user_account) {
        return petShowService.findPetsByUserAccount(user_account);
    }

    @RequestMapping(value = "findPetsByPetName",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findPetsByPetName(@RequestParam String pet_name) {
        return petShowService.findPetsByPetName(pet_name);
    }

    @RequestMapping(value ="delPetById",method = RequestMethod.DELETE)
    @ResponseBody
    public ReturnT<?> delPetById(@RequestParam int petId){
        return petShowService.delPetById(petId);
    }

    @RequestMapping(value = "query",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> showList(@RequestBody QueryCondition queryCondition){
        return petShowService.showList(queryCondition);
    }

    @RequestMapping(value = "findAll",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<?> findAll(){
        return petShowService.findAll();
    }
}
